package com.irdstudio.tdp.executor.core.plugin.migrate.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * 迁移治理任务类-[表名: 迁移治理任务(migrate_govern_task)]
 * 通过JDBC实现基本的数据表操作(CRUD) 
 * @author 代码自动生成
 * @version 1.0
 * @date 2020-11-04
 */
public class MigrateGovernTaskDao {

	/* 连接对象 */
	Connection conn = null;	

	public MigrateGovernTaskDao(Connection conn){
		this.conn = conn;
	}

	/**
	 * 根据主键查询单条记录
	 * @param 
	 * @return
	 * @throws SQLException
	 */
	public List<MigrateGovernTask> queryMigrateGovernTaskWithAll()
			throws SQLException {
		List<MigrateGovernTask> dcList = new ArrayList<MigrateGovernTask>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		MigrateGovernTask dc = null;
		try {
			ps = conn
					.prepareStatement("SELECT * FROM migrate_govern_task");
			rs = ps.executeQuery();
			while (rs.next()) {
				dc = new MigrateGovernTask();
				dc.setGovernTaskId(rs.getString("govern_task_id"));
				dc.setGovernSrcId(rs.getString("govern_src_id"));
				dc.setGovernTaskSrc(rs.getString("govern_task_src"));
				dc.setGovernTaskDesc(rs.getString("govern_task_desc"));
				dc.setImpactAnalysis(rs.getString("impact_analysis"));
				dc.setMigrateComment(rs.getString("migrate_comment"));
				dc.setDevComment(rs.getString("dev_comment"));
				dc.setTestComment(rs.getString("test_comment"));
				dc.setTechComment(rs.getString("tech_comment"));
				dc.setBusiComment(rs.getString("busi_comment"));
				dc.setSourceIncharge(rs.getString("source_incharge"));
				dc.setTargetIncharge(rs.getString("target_incharge"));
				dc.setGovernTaskState(rs.getString("govern_task_state"));
				dc.setTaskBeginDate(rs.getString("task_begin_date"));
				dc.setTaskRequireFinishDate(rs.getString("task_require_finish_date"));
				dc.setTaskRealFinishDate(rs.getString("task_real_finish_date"));
				dcList.add(dc);
			}
		} catch (SQLException e) {
			throw new SQLException("queryMigrateGovernTaskWithAll is Wrong!"
					+ e.getMessage());
		} finally {
			close(rs, null, ps);
		}
		return dcList;
	}

	/**
	 * 根据查询条件查询多条或单条记录
	 * @param szCondition 
	 * @return
	 * @throws SQLException
	 */
	public List<MigrateGovernTask> queryMigrateGovernTaskWithCond(String szCondition,String szOrderBy)
			throws SQLException {
		List<MigrateGovernTask> dcList = new ArrayList<MigrateGovernTask>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement("SELECT * FROM migrate_govern_task "
					+ szCondition + " " + szOrderBy);
			rs = ps.executeQuery();
			while (rs.next()) {
				MigrateGovernTask dc = new MigrateGovernTask();
				dc.setGovernTaskId(rs.getString("govern_task_id"));
				dc.setGovernSrcId(rs.getString("govern_src_id"));
				dc.setGovernTaskSrc(rs.getString("govern_task_src"));
				dc.setGovernTaskDesc(rs.getString("govern_task_desc"));
				dc.setImpactAnalysis(rs.getString("impact_analysis"));
				dc.setMigrateComment(rs.getString("migrate_comment"));
				dc.setDevComment(rs.getString("dev_comment"));
				dc.setTestComment(rs.getString("test_comment"));
				dc.setTechComment(rs.getString("tech_comment"));
				dc.setBusiComment(rs.getString("busi_comment"));
				dc.setSourceIncharge(rs.getString("source_incharge"));
				dc.setTargetIncharge(rs.getString("target_incharge"));
				dc.setGovernTaskState(rs.getString("govern_task_state"));
				dc.setTaskBeginDate(rs.getString("task_begin_date"));
				dc.setTaskRequireFinishDate(rs.getString("task_require_finish_date"));
				dc.setTaskRealFinishDate(rs.getString("task_real_finish_date"));
				dcList.add(dc);
			}
		} catch (SQLException e) {
			throw new SQLException("queryMigrateGovernTaskWithCond is Wrong!"
					+ e.getMessage());
		} finally {
			close(rs, null, ps);
		}
		return dcList;
	}

	/**
	 * 关闭资源
	 * @param theRs
	 * @param theStmt
	 * @param thePs
	 */
	protected void close(ResultSet theRs, Statement theStmt,
			PreparedStatement thePs) {
		try {
			if (theRs != null)
				theRs.close();
			if (theStmt != null)
				theStmt.close();
			if (thePs != null)
				thePs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
